package com.ww.hadoop.mr.fof;

import com.ww.hadoop.mr.topn.TKey;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;
import java.util.Iterator;

public class FReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
    IntWritable rval = new IntWritable();
    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Reducer<Text, IntWritable, Text, IntWritable>.Context context) throws IOException, InterruptedException {
        //key           value
        // y-x          1
        // y-x          0
        // y-x          1
        Iterator<IntWritable> iterator = values.iterator();
        int sum = 0;
        boolean isWrite = true;
        for (IntWritable value : values) {
            if (value.get() == 0) {
                isWrite =false;
                break;
            }
            sum++;
        }
        if (isWrite) {
            rval.set(sum);
            context.write(key,rval);
        }


    }
}
